package com.czl.module_park.adapter

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingAction
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.data.bean.CarAceessItemBean
import com.czl.module_park.R
import com.czl.module_park.databinding.ItemCarAccessBinding
import com.czl.module_park.fragment.CarAccessFragment

class CarAccessAdapter(val fragment: CarAccessFragment) :
    BaseQuickAdapter<CarAceessItemBean, BaseDataBindingHolder<ItemCarAccessBinding>>(
        R.layout.item_car_access
    ) {
    override fun convert(
        holder: BaseDataBindingHolder<ItemCarAccessBinding>,
        item: CarAceessItemBean
    ) {
        holder.dataBinding?.apply {
            data = item
            adapter = this@CarAccessAdapter
            executePendingBindings()
        }
    }

    val onActionClick:BindingCommand<Any> = BindingCommand(BindingConsumer {

        if (it is CarAceessItemBean){
            dealActionBtnClick(it)

        }
    })
    fun getCarAccessIoType(type:Int): String {
        return when(type){
            1->"入口"
            2->"出口"
            else->""
        }
    }
    fun getCarAccessDeviceStatus(deviceStatus:String?):ActionBtnStatus{
        return when(deviceStatus){
            "02"->ActionBtnStatus("离线","#999999")
            else-> ActionBtnStatus("","#999999")
        }
    }
    fun getActionBtnStatus(deviceStatus:String?):ActionBtnStatus{
        return when(deviceStatus){
            "02"->ActionBtnStatus("抬杆","#76E2BB")
            else->ActionBtnStatus("","#76E2BB")
        }

    }
    fun dealActionBtnClick(device: CarAceessItemBean){
        when(device.deviceStatus){
            "03"->{}
            "04"->{fragment.viewModel.carAccessAction(device)}
            "02"->fragment.showNormalToast("设备处于离线状态")
        }
    }
    data class ActionBtnStatus(val text:String,val color:String)
}